package com.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.core.exception.ParameterException;
import com.demo.dao.LearningResourcesDao;
import com.demo.domain.LearningResources;
import com.demo.service.LearningResourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LearningResourcesServiceImpl extends ServiceImpl<LearningResourcesDao, LearningResources> implements LearningResourcesService {
    @Autowired
    private LearningResourcesDao learningResourcesDao;

    /**
     * 分类得到所有学习资源
     * @param type
     * @return
     * @throws Exception
     */
    @Override
    public List<LearningResources> getAllResourcesByType(Integer type) throws Exception {
        if (type == null || type != 0 && type != 1) {
            throw new ParameterException("type为空或值非法");
        }
        LambdaQueryWrapper<LearningResources> lambdaQueryWrapper = new LambdaQueryWrapper<LearningResources>();
        lambdaQueryWrapper.like(LearningResources::getLrType, type);
        lambdaQueryWrapper.eq(LearningResources::getLrDelFlag,0);
        List<LearningResources> list = learningResourcesDao.selectList(lambdaQueryWrapper);
        return list;
    }
}
